home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch10 / TileHex.frm (.txt) < prev    next >
Visual Basic Form  |  1999-06-09  |  7KB  |  207 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTileHex 
  3.    Caption         =   "TileHex"
  4.    ClientHeight    =   4740
  5.    ClientLeft      =   1740
  6.    ClientTop       =   900
  7.    ClientWidth     =   5535
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4740
  11.    ScaleWidth      =   5535
  12.    Begin VB.PictureBox picCanvas 
  13.       AutoRedraw      =   -1  'True
  14.       Height          =   4335
  15.       Left            =   1200
  16.       ScaleHeight     =   285
  17.       ScaleMode       =   3  'Pixel
  18.       ScaleWidth      =   285
  19.       TabIndex        =   0
  20.       Top             =   0
  21.       Width           =   4335
  22.    End
  23.    Begin VB.Image imgTile 
  24.       Height          =   975
  25.       Index           =   5
  26.       Left            =   0
  27.       Picture         =   "TileHex.frx":0000
  28.       Top             =   1080
  29.       Width           =   1110
  30.    End
  31.    Begin VB.Image imgMask 
  32.       Height          =   975
  33.       Index           =   5
  34.       Left            =   840
  35.       Picture         =   "TileHex.frx":3922
  36.       Top             =   1080
  37.       Visible         =   0   'False
  38.       Width           =   1110
  39.    End
  40.    Begin VB.Image imgTile 
  41.       Height          =   405
  42.       Index           =   4
  43.       Left            =   0
  44.       Picture         =   "TileHex.frx":3C78
  45.       Top             =   4320
  46.       Width           =   465
  47.    End
  48.    Begin VB.Image imgMask 
  49.       Height          =   405
  50.       Index           =   4
  51.       Left            =   600
  52.       Picture         =   "TileHex.frx":46DA
  53.       Top             =   4320
  54.       Visible         =   0   'False
  55.       Width           =   465
  56.    End
  57.    Begin VB.Image imgMask 
  58.       Height          =   405
  59.       Index           =   3
  60.       Left            =   600
  61.       Picture         =   "TileHex.frx":4E7C
  62.       Top             =   3840
  63.       Visible         =   0   'False
  64.       Width           =   465
  65.    End
  66.    Begin VB.Image imgTile 
  67.       Height          =   405
  68.       Index           =   3
  69.       Left            =   0
  70.       Picture         =   "TileHex.frx":561E
  71.       Top             =   3840
  72.       Width           =   465
  73.    End
  74.    Begin VB.Image imgTile 
  75.       Height          =   735
  76.       Index           =   2
  77.       Left            =   0
  78.       Picture         =   "TileHex.frx":5DC0
  79.       Top             =   3000
  80.       Width           =   735
  81.    End
  82.    Begin VB.Image imgMask 
  83.       Height          =   735
  84.       Index           =   2
  85.       Left            =   840
  86.       Picture         =   "TileHex.frx":6BF6
  87.       Top             =   3000
  88.       Visible         =   0   'False
  89.       Width           =   735
  90.    End
  91.    Begin VB.Image imgTile 
  92.       Height          =   735
  93.       Index           =   1
  94.       Left            =   0
  95.       Picture         =   "TileHex.frx":7A2C
  96.       Top             =   2160
  97.       Width           =   735
  98.    End
  99.    Begin VB.Image imgMask 
  100.       Height          =   735
  101.       Index           =   1
  102.       Left            =   840
  103.       Picture         =   "TileHex.frx":8862
  104.       Top             =   2160
  105.       Visible         =   0   'False
  106.       Width           =   735
  107.    End
  108.    Begin VB.Image imgMask 
  109.       Height          =   975
  110.       Index           =   0
  111.       Left            =   840
  112.       Picture         =   "TileHex.frx":9698
  113.       Top             =   0
  114.       Visible         =   0   'False
  115.       Width           =   1110
  116.    End
  117.    Begin VB.Image imgTile 
  118.       Height          =   975
  119.       Index           =   0
  120.       Left            =   0
  121.       Picture         =   "TileHex.frx":99EE
  122.       Top             =   0
  123.       Width           =   1110
  124.    End
  125. Attribute VB_Name = "frmTileHex"
  126. Attribute VB_GlobalNameSpace = False
  127. Attribute VB_Creatable = False
  128. Attribute VB_PredeclaredId = True
  129. Attribute VB_Exposed = False
  130. Option Explicit
  131. Private TileChoice As Integer
  132. Private ColDx() As Integer
  133. Private RowDx() As Integer
  134. Private RowDy() As Integer
  135. ' Tile the PictureBox with the image in the image control.
  136. Private Sub TilePicture(ByVal pic As PictureBox, ByVal tile_image As Image, ByVal mask_image As Image, ByVal cdx As Integer, ByVal rdx As Integer, ByVal rdy As Integer)
  137. Dim wid As Single
  138. Dim hgt As Single
  139. Dim x As Integer
  140. Dim y As Integer
  141. Dim x1 As Integer
  142. Dim x2 As Integer
  143. Dim startx As Integer
  144.     pic.Cls     ' Clear the picture box.
  145.     ' Start above and to the left of the drawing area.
  146.     wid = tile_image.Parent.ScaleX(tile_image.Width, tile_image.Parent.ScaleMode, pic.ScaleMode)
  147.     hgt = tile_image.Parent.ScaleY(tile_image.Height, tile_image.Parent.ScaleMode, pic.ScaleMode)
  148.     y = -hgt
  149.     x1 = -wid
  150.     x2 = x1 + rdx
  151.     startx = x1
  152.     ' Copy the tile until we're to the right and
  153.     ' below the drawing area.
  154.     Do While y <= pic.ScaleHeight
  155.         x = startx
  156.         Do While x <= pic.ScaleWidth
  157.             ' Copy the mask with vbMergePaint.
  158.             pic.PaintPicture mask_image.Picture, x, y, , , , , , , vbMergePaint
  159.             ' Copy the mask with vbSrcAnd.
  160.             pic.PaintPicture tile_image.Picture, x, y, , , , , , , vbSrcAnd
  161.             x = x + cdx
  162.         Loop
  163.         If startx = x1 Then
  164.             startx = x2
  165.         Else
  166.             startx = x1
  167.         End If
  168.         y = y + rdy
  169.     Loop
  170. End Sub
  171. ' Initialize row and column offsets.
  172. Private Sub Form_Load()
  173.     ReDim ColDx(imgTile.LBound To imgTile.UBound)
  174.     ReDim RowDx(imgTile.LBound To imgTile.UBound)
  175.     ReDim RowDy(imgTile.LBound To imgTile.UBound)
  176.     ColDx(0) = 108
  177.     RowDx(0) = 54
  178.     RowDy(0) = 31
  179.     ColDx(1) = 72
  180.     RowDx(1) = 35
  181.     RowDy(1) = 20
  182.     ColDx(2) = ColDx(1)
  183.     RowDx(2) = RowDx(1)
  184.     RowDy(2) = RowDy(1)
  185.     ColDx(3) = ColDx(1)
  186.     RowDx(3) = RowDx(1)
  187.     RowDy(3) = RowDy(1)
  188.     ColDx(4) = 46
  189.     RowDx(4) = 23
  190.     RowDy(4) = 13
  191.     ColDx(5) = 108
  192.     RowDx(5) = 54
  193.     RowDy(5) = 31
  194. End Sub
  195. ' Tile the form.
  196. Private Sub Form_Resize()
  197. Dim wid As Single
  198.     wid = ScaleWidth - picCanvas.Left
  199.     If wid < 120 Then wid = 120
  200.     picCanvas.Move picCanvas.Left, 0, wid, ScaleHeight
  201.     TilePicture picCanvas, imgTile(TileChoice), imgMask(TileChoice), ColDx(TileChoice), RowDx(TileChoice), RowDy(TileChoice)
  202. End Sub
  203. Private Sub imgTile_Click(Index As Integer)
  204.     TileChoice = Index
  205.     TilePicture picCanvas, imgTile(TileChoice), imgMask(TileChoice), ColDx(TileChoice), RowDx(TileChoice), RowDy(TileChoice)
  206. End Sub
  207.